package com.attilax.acc;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

import aaaCasher.SqlParser;
import aaaCfg.IocX4casher;

import com.attilax.db.DBX;
import com.google.inject.Inject;

public class AccService {
	
	public static void main(String[] args) {
		   AccService accS=IocX4casher.getBean(AccService.class);
		   System.out.println(accS.getNowMoney("aamaoaamao"));
		//   accS.createAcc("acc_attilax",12.56);
		//   Query
	//	 int r=  accS.reduceAmount("uu", 12.56);
	//	 System.out.println("--ret :"+String.valueOf(r));
	}
	
	

	public void createAcc(String uname, double d) {
		 String   $sql = "insert into   ecs_users( "+
		            "   user_name,user_money )values('@u@',  "+String.valueOf(d)+"" +
		           
		            " )";
		 $sql= $sql.replace("@u@", uname);
		  
		  System.out.println("---"+  $sql);
			
		  
		int r=	dbx.execSql_retInt($sql);
		System.out.println("----ret int:"+String.valueOf(r));
		
	}



	@Inject
	DBX dbx;
	public int reduceAmount(String uid, Double i) {
		
		//DataLogicSales
		// TODO Auto-generated method stub
		
		
		 /* 更新用户信息 */
	  String   $sql = "UPDATE   ecs_users "+
	            " SET user_money = user_money - "+String.valueOf(i)+"" +
	           
	            " WHERE user_name = '"+uid+"' LIMIT 1";
	  
	  System.out.println("---"+  $sql);
		
	  
	int r=	dbx.execSql_retInt($sql);
	System.out.println("----ret int:"+String.valueOf(r));
		return r;
	}



	public double getNowMoney(String uid) {
		 String   $sql = "select * from   ecs_users "+ 
		           
		            " WHERE user_name = '"+uid+"' LIMIT 1";
		Map m= dbx.uniqueResult($sql);
		return Double.parseDouble( m.get("user_money").toString());
	}

}
